<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<!DOCTYPE html>
<html>
<head>
    <title>添加用户</title>
    <link rel="stylesheet" href="/bootstrap/css/bootstrap.min.css">
    <script src="/bootstrap/js/jquery.min.js"></script>
    <script src="/bootstrap/js/bootstrap.min.js"></script>
    <style>
        body {
            padding-top: 20px;
        }
        .panel-heading h1 {
            font-size: 24px;
            margin: 0;
        }
        .panel-footer {
            font-size: 12px;
        }
        .form-group {
            margin-bottom: 20px;
        }
        label {
            font-weight: bold;
            width: 120px;
            display: inline-block;
        }
        input[type="text"],
        select {
            width: 300px;
            padding: 10px;
            border: 1px solid #ccc;
            border-radius: 4px;
            box-shadow: inset 0 1px 1px rgba(0,0,0,0.075);
            transition: border-color ease-in-out 0.15s, box-shadow ease-in-out 0.15s;
        }
        input[type="text"]:focus,
        select:focus {
            outline: none;
            border-color: #66afe9;
            box-shadow: 0 0 8px #66afe9;
        }
        button[type="submit"] {
            margin-top: 10px;
        }
    </style>
    <style>
        .form-group select {
            width: 120px;
        }
    </style>
</head>
<body>
<div class="container">
    <div class="panel panel-success">
        <div class="panel-heading panel-title text-center">
            <h1>添加用户信息</h1>
        </div>
        <div class="panel-body" align="center">
            <form method="post" action="/users/add" role="form">
                <div class="form-group">
                    <label for="img">头像:</label>
                    <input type="file" style="width: 300px" class="form-control" id="img" name="img" width="50%">
                </div>
                <div class="form-group">
                    <label for="username">用户名:</label>
                    <input type="text" class="form-control" id="username" name="username" required placeholder="请输入用户名...">
                </div>
                <div class="form-group">
                    <label for="password">密码:</label>
                    <input type="text" class="form-control" id="password" name="password" required placeholder="请输入密码...">
                </div>
                <div class="form-group">
                    <label for="phone">电话:</label>
                    <input type="text"  class="form-control" id="phone" name="phone"  maxlength="11" pattern="\d{11}" required placeholder="请输入手机号...">
                </div>
                <div class="form-group">
                    <label for="role">角色:</label>
                    <select class="form-control" id="role" name="role">
                        <option value="teacher">老师</option>
                        <option value="student">学生</option>
                        <option value="manager">管理员</option>
                    </select>
                </div>
                <%--                <div class="form-group">--%>
                <%--                    <label for="create_time">创建时间:</label>--%>
                <%--                    <input type="text" class="form-control" id="create_time" name="create_time" readonly value="">--%>
                <%--                </div>--%>
                <div class="form-group">
                    <label for="locked">是否锁定:</label>
                    <input type="checkbox" id="locked" name="locked">
                </div>
                <button type="submit" class="btn btn-primary">添加</button>
            </form>
        </div>
        <div class="panel-footer text-right">
            百度在线考试平台
        </div>
    </div>
</div>
</body>
<script>
    $(function (){
        $("#username").blur(function (){
            $.get("/users/validname",{username:$(this).val()},function (res){
                if (res!='0'){
                    alert("该账号已被注册！");
                    var button = document.getElementById("btn");
                    button.disabled = true;
                }
            })
        })
    })

    $(function (){
        $("#username").change(function (){
            $.get("/users/validname",{username:$(this).val()},function (res){
                if (res=='0'){
                    var button = document.getElementById("btn");
                    button.disabled = false;
                }
            })
        })
    })
    $(function (){
        $("#phone").blur(function (){
            $.get("/users/verifyPhone",{phone:$(this).val()},function (res){
                if (res!='0'){
                    alert("该手机号已被注册！");
                    var button = document.getElementById("btn");
                    button.disabled = true;
                }
            })
        })
    })

    $(function (){
        $("#phone").change(function (){
            $.get("/users/verifyPhone",{phone:$(this).val()},function (res){
                if (res=='0'){
                    var button = document.getElementById("btn");
                    button.disabled = false;
                }
            })
        })
    })
</script>
</html>
